@extends('layouts.back_stage')
@section('content')
    <style>
        .info_box{width:100%;height:30px;margin-top:20px;}
        .info_box li{width:25%;float:left;height:30px;}
        .info_box li h3{display: inline;}
        .lining-btn{width:100%;height:40px;margin:30px 0;}
        .lining-btn .lining-a{width:80px;text-align:center;line-height:40px;display:block;background:#00ccff;color:#fff;float:left;margin-left:30px;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;}
        .lining-ul{color:#383838; width:80%;height:auto;margin:0 auto;}
        .plan{border-collapse:collapse;width:100%;font-size:14px;color:#383838;background:#fff;}
        .plan td{text-align:center;height:35px;width: 100px;}
        table,th,td{border:1px solid #ccc;width: 100px;}
        .input{width:100%;height:100%;border:0;outline:none;text-align:center;}
        .saveBt{float:right;margin-top:30px;}
    </style>
    <div class="container">
        <div>
            <ul class="info_box">
                <li><h3>款号：<span class="getGirard">{{$investment->girard}}</span></h3></li>
                <li><h3>波段：{{ $investment->band_name }}</h3></li>
                <li><h3>品类：{{ $category[$investment->cate_id] }}</h3></li>
                <li><h3>入库量：{{$investment->storage_volume}}</h3></li>
            </ul>
        </div>
        <div class="lining-btn">
            @if(count($goods) >0 )
                @foreach($goods as $k=>$v)
                    <a class="lining-a" id="l{{ $v->id }}">{{ $v->color }}</a>
                @endforeach
            @endif
        </div>
        <ul class="lining-ul">
            @if(count($goods) >0 )
            @foreach($goods as $k=>$val)
            <li class="lining-li">
                <h3>盘点</h3>
                <table class="plan" border="1" cellspacing="0" cellpadding="0">
                    <tr>
                        <td>尺码：</td>
                        <?php
                        $size = explode(',',$val->size);
                        ?>
                        @foreach($size as $v)
                            <td class="col-md-1">{{ $v }}</td>
                        @endforeach
                    </tr>
                    <tr>
                        <?php
                        $size_stock = explode(',',$val->stock);
                        ?>
                            <td>盘点件数：</td>

                            @foreach($size_stock as $vv)
                                <td><input type="text" class="form-control numCount{{ $val->id }} input" value="{{$vv}}" placeholder="盘点数量" /></td>
                            @endforeach
                    </tr>
                </table>
                <button class="btn btn-primary saveBt" abc="{{ $val->id }}">保存</button>
            </li>
            @endforeach
            @endif
        </ul>
    </div>
    <script>
        /*初始化tab切换*/
        $(".lining-a:eq(0)").css("background","#27c24c");
        $(".lining-ul .lining-li").css("display","none");
        $(".lining-ul .lining-li:eq(0)").css("display","block")
        /*点击tab切换*/
        $(".lining-btn").children(".lining-a").click(function(){
            var n=$(this).index();
            $(this).css("background","#27c24c").siblings().css("background","#00ccff");
            $(".lining-ul .lining-li").css("display","none");
            $(".lining-ul .lining-li:eq("+n+")").css("display","block")
        });
        /*保存*/
        $(".saveBt").click(function(){
            var s = "";
            var id=$(this).attr("abc");
            $('.numCount'+id).each(function () {
                if($(this).val() == ''){
                    s += -999+',';
                }else {
                    s += $(this).val()+',';
                }
            });
            var stock=s.substr(0, s.length - 1);
            if (stock.indexOf("-999") == -1) {
                $.ajax({
                    url:'/storage/sizeStockSave',
                    type:'post',
                    data:{
                        'id':id,
                        'stock':stock,
                        'girard':$('.getGirard').text()
                    },
                    headers: {'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
                    dataType:'json',
                    success:function(data){
                        if(data.success){
                            $(".faceImg").attr("src","/img/laugh.png");
                            $(".oHandle").text("保存成功");
                            $(".oSuccess").show(0).delay(1000).hide(0);
                        }else{
                            $(".faceImg").attr("src","/img/weep.png");
                            $(".oHandle").text("保存失败");
                            $(".oSuccess").show(0).delay(1000).hide(0);
                        }
                    }
                })
            } else {
                $(".faceImg").attr("src","/img/weep.png");
                $(".oHandle").text("盘点数量不能为空");
                $(".oSuccess").show(0).delay(1000).hide(0);
            }
        });
        /*实际生产件数*/
        $(".input").bind("input","onpropertychange",function(){
            $(this).val($(this).val().replace(/[^\d]/g,""));
        });
    </script>
@endsection